import Vue from 'vue'
import VueRouter from 'vue-router'
import ContentLayoutView from "@/views/ContentLayoutView";
import HomeView from "@/views/web/HomeView";
import PoetryView from "@/views/web/PoetryView";
import ArticleView from "@/views/web/ArticleView";
import ClassicsView from "@/views/web/ClassicsView";
let originPush =  VueRouter.prototype.push;  //备份原push方法

VueRouter.prototype.push = function (location, resolve, reject){
    if (resolve && reject) {    //如果传了回调函数，直接使用
        originPush.call(this, location, resolve, reject);
    }else {                     //如果没有传回调函数，手动添加
        originPush.call(this, location, ()=>{}, ()=>{});
    }
}

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'app',
        component: ContentLayoutView,
        children: [
            {
                path: '/',
                component: HomeView,
            },
            {
                path: '/app/p',
                name: 'p',
                component: PoetryView, // 诗词
            },
            {
                path: '/app/w',
                name: 'w',
                component: ArticleView, // 文章
            },
            {
                path: '/app/j',
                name: 'j',
                component: ClassicsView, // 经
            },
            {
                path: '/app/d',
                name: 'd',
                component: PoetryView, // 典籍
            }
        ]
    },
    {
        path: '/about',
        name: 'about',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: function () {
            return import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
        }
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router
